﻿using System;
using System.Collections.Generic;
using System.Text;
using Eleanor.DAL;
using System.IO;
using System.Text.RegularExpressions;
using System.Data;

namespace Eleanor.BLL
{
    public class PaintingBLL
    {
        protected PaintingDAL paintingDAL = new PaintingDAL();
        protected TagDAL tagDAL = new TagDAL();
        protected HottestPaintingDAL hottestPaintingDAL = new HottestPaintingDAL();

        public int Insert(dynamic painting)
        {
            return paintingDAL.Insert(painting);
        }

        public int CreateSimplePainting(string paintingNumber)
        {
            dynamic painting = paintingDAL.Select(paintingNumber);
            if (painting == null)
            {
                return paintingDAL.GeneratePaintingId(paintingNumber);
            }
            return painting.PaintingId;
        }

        public dynamic GetPainting(string paintingNumber)
        {
            return paintingDAL.Select(paintingNumber);
        }

        public dynamic Get(int paintingId)
        {
            return paintingDAL.Select(paintingId);
        }

        public List<dynamic> GetAll()
        {
            return paintingDAL.SelectAll();
        }

        public int Update(dynamic painting)
        {
            return paintingDAL.Update(painting);
        }

        public int Import(dynamic painting)
        {
            return paintingDAL.Import(painting);
        }

        public dynamic Search(dynamic condition, int pageIndex, int pageSize)
        {
            return paintingDAL.Select(condition, pageIndex, pageSize);
        }

        public List<dynamic> GetAllFrames()
        {
            return paintingDAL.SelectAllFrames();
        }

        public List<dynamic> GetTags(int paintingId)
        {
            return tagDAL.SelectByPaintingId(paintingId);
        }

        public string GetVirtualFolderPath(int paintingId)
        {
            int fristLevel = paintingId / 10000000;
            int secondLevel = paintingId / 1000;
            return "/" + fristLevel.ToString("D4") + "/" + secondLevel.ToString("D4");
        }

        public string GetLocalFolderPath(int paintingId)
        {
            int fristLevel = paintingId / 10000000;
            int secondLevel = paintingId / 1000;
            return fristLevel.ToString("D4") + "\\" + secondLevel.ToString("D4");
        }

        public void ImprotHottestPainting(string paintingNumbers)
        {
            hottestPaintingDAL.Import(paintingNumbers);
        }

        public List<dynamic> GetAllHottestPaintings()
        {
            return hottestPaintingDAL.SelectAll();
        }

        public List<dynamic> GetRelatedPaintings(int paintingId)
        {
            return paintingDAL.SelectRelated(paintingId);
        }

        public DataTable GetExportDataTable(string paintingNummbers)
        {
            return paintingDAL.SelectMulti(paintingNummbers);
        }
    }
}